
#include <pthread.h>

namespace glf {

struct Mutex::Impl {
	pthread_mutex_t mMutex;

	Impl(int) {
		pthread_mutexattr_t attr; //need to keep attr ?!?
		pthread_mutexattr_init(&attr); //PTHREAD_MUTEX_RECURSIVE
		pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
		
		int result = pthread_mutex_init(&mMutex, &attr);
		result = result;

		pthread_mutexattr_destroy(&attr); 
	}

	~Impl() {
		pthread_mutex_destroy(&mMutex);
	}

	void Lock() {
		int result = pthread_mutex_lock(&mMutex);
		result = result;
	}

	bool TryLock() {
		return pthread_mutex_trylock(&mMutex) == 0;
	}

	void Unlock() {
		int result = pthread_mutex_unlock(&mMutex);
		result = result;
	}
};

} //namespace glf

